﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace RiskMan.DataClass.Models.RM
{
    [Serializable]
    public class ModuleLimitStockModel: ISerializable, INotifyPropertyChanged
    {
        #region private
        private bool _check;
        private String _account;
        private List<String> _accountList;
        private bool _isRun;
        private String _clientCode;
        private List<String> _clientCodeList;
        private bool _isAllowClose;
        private DateTime _startTimeClose;
        private DateTime _endTimeClose;

        private String _seccode;
        private String _regim;
        private List<String> _seccodeList;
        private int _currentPos;
        private int _limitStock;
        private string _status;
        private int _id;
        private DateTime _timeSend;
        #endregion

        #region public

        public bool Check
        {
            get { return _check; }
            set
            {
                if (_check != value)
                {
                    _check = value;
                    RaisePropertyChanged("Check");
                }
            }
        }

        /// <summary>
        /// Время, с которого нужно контролировать трейдера по количеству контарктов (автоматическое закрытие)
        /// </summary>
        public DateTime StartTimeClose
        {
            get { return _startTimeClose; }
            set
            {
                if (_startTimeClose != value)
                {
                    _startTimeClose = value;
                    RaisePropertyChanged("StartTimeClose");
                }
            }
        }

        /// <summary>
        /// Время, до которого нужно контролировать трейдера по количеству контарктов (автоматическое закрытие)
        /// </summary>
        public DateTime EndTimeClose
        {
            get { return _endTimeClose; }
            set
            {
                if (_endTimeClose != value)
                {
                    _endTimeClose = value;
                    RaisePropertyChanged("EndTimeClose");
                }
            }
        }

        public String Account
        {
            get { return _account; }
            set
            {
                if (_account != value)
                {
                    _account = value;
                    RaisePropertyChanged("Account");
                }
            }
        }

        /// <summary>
        /// Статус отправленной заявки на закрытие контрактов превышающих лимит
        /// </summary>
        public String Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    RaisePropertyChanged("Status");
                }
            }
        }

        /// <summary>
        /// ID отправленной заявки на закрытие контрактов превышающих лимит
        /// </summary>
        public int ID
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    _id = value;
                    RaisePropertyChanged("ID");
                }
            }
        }

        /// <summary>
        /// Время отправленной заявки на закрытие контрактов превышающих лимит
        /// </summary>
        public DateTime TimeSend
        {
            get { return _timeSend; }
            set
            {
                if (_timeSend != value)
                {
                    _timeSend = value;
                    RaisePropertyChanged("TimeSend");
                }
            }
        }

        public List<String> AccountList
        {
            get { return _accountList; }
            set
            {
                if (_accountList != value)
                {
                    _accountList = value;
                    RaisePropertyChanged("AccountList");
                }
            }
        }
        public String ClientCode
        {
            get { return _clientCode; }
            set
            {
                if (_clientCode != value)
                {
                    _clientCode = value;
                    RaisePropertyChanged("ClientCode");
                }
            }

        }
        public List<String> ClientCodeList
        {
            get { return _clientCodeList; }
            set
            {
                if (_clientCodeList != value)
                {
                    _clientCodeList = value;
                    RaisePropertyChanged("ClientCodeList");
                }
            }
        }

        /// <summary>
        /// Автоматическое закрытие контрактов, превышающих лимит
        /// </summary>
        public bool IsAllowClose
        {
            get { return _isAllowClose; }
            set
            {
                if (_isAllowClose != value)
                {
                    _isAllowClose = value;
                    RaisePropertyChanged("IsAllowClose");
                }
            }
        }

        public String Seccode
        {
            get { return _seccode; }
            set
            {
                if (_seccode != value)
                {
                    _seccode = value;
                    RaisePropertyChanged("Seccode");
                }
            }
        }
        public List<String> SeccodeList
        {
            get { return _seccodeList; }
            set
            {
                if (_seccodeList != value)
                {
                    _seccodeList = value;
                    RaisePropertyChanged("SeccodeList");
                }
            }
        }
        public int CurrentPos
        {
            get { return _currentPos; }
            set
            {
                if (_currentPos != value)
                {
                    _currentPos = value;
                    RaisePropertyChanged("CurrentPos");
                }
            }
        }

        public int LimitStock
        {
            get { return _limitStock; }
            set
            {
                if (_limitStock != value)
                {
                    _limitStock = value;
                    RaisePropertyChanged("LimitStock");
                }
            }
        }

        public bool IsRun
        {
            get { return _isRun; }
            set
            {
                if (_isRun != value)
                {
                    _isRun = value;
                    RaisePropertyChanged("IsRun");
                }
            }
        }


        public string Regim
        {
            get { return _regim; }
            set
            {
                if (_regim != value)
                {
                    _regim = value;
                    RaisePropertyChanged("Regim");
                }
            }
        }

        #endregion

        #region OnPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        
        #endregion

        public ModuleLimitStockModel() { }

        public ModuleLimitStockModel(SerializationInfo info, StreamingContext context)
        {
            Check = info.GetBoolean("Check");
            Account = info.GetString("Account");
            AccountList = (List<String>)info.GetValue("AccountList", typeof(List<String>));
            ClientCode = info.GetString("ClientCode");
            ClientCodeList = (List<String>)info.GetValue("ClientCodeList", typeof(List<String>));
            Seccode = info.GetString("Seccode");
            SeccodeList = (List<String>)info.GetValue("SeccodeList", typeof(List<String>));
            CurrentPos = info.GetInt32("CurrentPos");
            LimitStock = info.GetInt32("LimitStock");
            IsRun = info.GetBoolean("IsRun");
            Regim = info.GetString("Regim");
            IsAllowClose = info.GetBoolean("IsAllowClose");
            Status = info.GetString("Status");
            ID = info.GetInt32("ID");
            TimeSend = info.GetDateTime("TimeSend");
            StartTimeClose = info.GetDateTime("StartTimeClose");
            EndTimeClose = info.GetDateTime("EndTimeClose");
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Check", Check);
            info.AddValue("Account", Account);
            info.AddValue("AccountList", AccountList);
            info.AddValue("ClientCode", ClientCode);
            info.AddValue("ClientCodeList", ClientCodeList);
            info.AddValue("Seccode", Seccode);
            info.AddValue("SeccodeList", SeccodeList);
            info.AddValue("CurrentPos", CurrentPos);
            info.AddValue("LimitStock", LimitStock);
            info.AddValue("IsRun",IsRun);
            info.AddValue("Regim", Regim);
            info.AddValue("IsAllowClose", _isAllowClose);
            info.AddValue("Status", Status);
            info.AddValue("ID", ID);
            info.AddValue("TimeSend", TimeSend);
            info.AddValue("StartTimeClose", StartTimeClose);
            info.AddValue("EndTimeClose", EndTimeClose);
        }
    }
}
